package com.shangguosha.model.cards;

import com.shangguosha.model.Character;
import com.shangguosha.model.enums.Suit;

/**
 * 闪卡牌
 */
public class Dodge extends BasicCard {
    
    public Dodge(String id, Suit suit, int number) {
        super(id, "闪", suit, number, "抵消一次【杀】的效果");
    }

    public Dodge(String id, String name, Suit suit, int number) {
        super(id, name, suit, number, "抵消一次【杀】的效果");
    }
    
    @Override
    public boolean canUse(Character player, Character target) {
        // 闪通常不能主动使用，只能在响应杀时使用
        // 这里返回false，实际使用时通过特殊逻辑处理
        return false;
    }
    
    @Override
    public void use(Character player, Character target) {
        // 闪的使用逻辑通常在响应杀时处理
        emit("dodge_used", player, this);
        System.out.printf("%s 使用了【闪】%n", player.getName());
    }
    
    /**
     * 响应杀时使用闪
     */
    public boolean canDodge(Character player) {
        return player != null && player.isAlive() && player.hasCard(this);
    }
    
    /**
     * 执行闪避
     */
    public void dodge(Character player) {
        if (canDodge(player)) {
            player.discardCard(this);
            emit("dodge_executed", player, this);
            System.out.printf("%s 使用【闪】抵消了【杀】的效果%n", player.getName());
        }
    }
    
    @Override
    public String getEffectDescription() {
        return "抵消一次【杀】的效果";
    }
    
    @Override
    public Dodge clone() {
        return new Dodge(getId() + "_clone", getSuit(), getNumber());
    }
}